package com.linshengjian.core;

import java.io.Serializable;

public abstract class BaseModel<ID extends Comparable<ID>> implements Serializable, Comparable {

    private ID id;

    public ID getId() {
        return id;
    }

    public void setId(ID id) {
        this.id = id;
    }

    public boolean isNew() {
        return null == id ? true : false;
    }

    @Override
    public int compareTo(Object obj) {
        BaseModel<ID> baseModel = (BaseModel) obj;
        return getId().compareTo(baseModel.getId());
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        BaseModel<?> baseModel = (BaseModel<?>) o;

        return id != null ? id.equals(baseModel.id) : baseModel.id == null;
    }

    @Override
    public int hashCode() {
        return id != null ? id.hashCode() : 0;
    }
}
